/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */


#include "usart.h"
#include <string.h>
#include <stdio.h>
#include "../LED/led_interface.h"
#include "../ShowMSG/ShowMSG_interface.h"
#include "../LCD_TFT/bsp_lcd.h"
#include "../KeyScan/KeyScan.h"
#include "../W25QXX/W25QXX.h"
//#define TASK_CONTROL
//#define QUEUE_TEST
//#define QUEUESAMPOR
//#define BINARY_SEMAPHOR
#define LED
static int counter=0;
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
void StorePassword(uint8_t key);
void DeleteLastCharacter(void);
void ClearPassword();
void Format_display(char key);
void Format_display_ty(char *origin,char *detect);
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

#define PASSWORD_LENGTH 6
uint8_t password[PASSWORD_LENGTH] = {0x00};
int password_index = 0;
char key;
//    char str[50];
char buffer[20];
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
osThreadId mytTask1Handle;
osThreadId myTask02Handle;
osThreadId myTask03_key0Handle;
osThreadId myTask04_key1Handle;
osMessageQId myQueue01Handle;
osMutexId myMutex01Handle;
osSemaphoreId myBinarySemLEDHandle;
osSemaphoreId myCountingSem01Handle;

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void StartDefaultTask(void const * argument);
void StartTask02(void const * argument);
void StartTask03(void const * argument);
void StartTask04(void const * argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );

/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
static StaticTask_t xIdleTaskTCBBuffer;
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];

void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
  *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
  *ppxIdleTaskStackBuffer = &xIdleStack[0];
  *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
  /* place for user code */
}
/* USER CODE END GET_IDLE_TASK_MEMORY */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */
  /* Create the mutex(es) */
  /* definition and creation of myMutex01 */
  osMutexDef(myMutex01);
  myMutex01Handle = osMutexCreate(osMutex(myMutex01));

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* Create the semaphores(s) */
  /* definition and creation of myBinarySemLED */
  osSemaphoreDef(myBinarySemLED);
  myBinarySemLEDHandle = osSemaphoreCreate(osSemaphore(myBinarySemLED), 1);

  /* definition and creation of myCountingSem01 */
  osSemaphoreDef(myCountingSem01);
  myCountingSem01Handle = osSemaphoreCreate(osSemaphore(myCountingSem01), 10);

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* definition and creation of myQueue01 */
  osMessageQDef(myQueue01, 16, uint16_t);
  myQueue01Handle = osMessageCreate(osMessageQ(myQueue01), NULL);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* definition and creation of mytTask1 */
  osThreadDef(mytTask1, StartDefaultTask, osPriorityNormal, 0, 128);
  mytTask1Handle = osThreadCreate(osThread(mytTask1), NULL);

  /* definition and creation of myTask02 */
  osThreadDef(myTask02, StartTask02, osPriorityIdle, 0, 128);
  myTask02Handle = osThreadCreate(osThread(myTask02), NULL);

  /* definition and creation of myTask03_key0 */
  osThreadDef(myTask03_key0, StartTask03, osPriorityIdle, 0, 128);
  myTask03_key0Handle = osThreadCreate(osThread(myTask03_key0), NULL);

  /* definition and creation of myTask04_key1 */
  osThreadDef(myTask04_key1, StartTask04, osPriorityIdle, 0, 128);
  myTask04_key1Handle = osThreadCreate(osThread(myTask04_key1), NULL);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

}

/* USER CODE BEGIN Header_StartDefaultTask */
/**
  * @brief  Function implementing the defaultTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const * argument)
{
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
#ifdef TASK_CONTROL
  for(;;)
  {
      HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_RESET);
      osDelay(500);
      HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_SET);
      osDelay(500);
  }
#endif

#ifdef QUEUE_TEST
    for(;;)
  {
      osDelay(500);
  }
#endif

#ifdef  QUEUESAMPOR
    for(;;)
    {
        osDelay(10); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef BINARY_SEMAPHOR
    for(;;)
    {
        osDelay(10); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef LED
    for(;;)
    {
        // LED 控制
//        LED_On();
        HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_RESET);
        osDelay(500);
        HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_SET);
        osDelay(500);

    }
#endif

  /* USER CODE END StartDefaultTask */
}

/* USER CODE BEGIN Header_StartTask02 */
/**
* @brief Function implementing the myTask02 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask02 */
void StartTask02(void const * argument)
{
  /* USER CODE BEGIN StartTask02 */
  /* Infinite loop */
#ifdef TASK_CONTROL
  BaseType_t xReturn = pdPASS;/* 定义�??????????个创建信息返回�?�，默认为pdPASS */
  for(;;)
  {
      // 等待信号�??????????
      HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_RESET);
      osDelay(1000);
      HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_SET);
      osDelay(1000);

  }
#endif


#ifdef QUEUE_TEST
    uint8_t buttonPressed2 = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    uint32_t data2;
    char buffer[50];
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin) == GPIO_PIN_RESET){
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin) == GPIO_PIN_RESET)
            {
                //buttonPressed2 = 1; // 标志按钮已按�????????
                BaseType_t status= xQueueReceive(myQueue01Handle,&data2,0);
                if(status!=pdPASS){
                    HAL_UART_Transmit(&huart1, (uint8_t *)"read queue error\n", sizeof("read queue error\n"), 200);
                }else{
                    // �?????? data2 转换为字符串
                    printf("data:%ld",data2);
                }
            }

            while(HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin) == GPIO_PIN_RESET);
        }


       // osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef  QUEUESAMPOR
    for(;;)
    {
        osDelay(10); // 延迟，防止任务占用过多CPU时间
    }
#endif


#ifdef BINARY_SEMAPHOR
    for(;;)
    {
        osDelay(10); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef LED


    for (;;) {
        key = Keypad_Scan();
        // 显示当前键�??
        if (key) {
            HAL_UART_Transmit(&huart1,(uint8_t *)("hello"),8,200);
            Format_display(key);
            //Format_display_ty("ORIGIN STR: ",&key);
            //sprintf(buffer,  "KEY VALUE IS: %c", key);//阻碍线程
            //ST7735_DrawString(10, 50, buffer, RED, GRAY2, 1);
           // showStr(buffer);
            //处理按键输入
            switch (key) {
                case 'A': {
                    DeleteLastCharacter();
                    break;
                }
                case 'B': {
                    ClearPassword();
                    break;
                }
                case '#':{

                    uint8_t * temp=ReadPassword();
                    showStr("-------------------------\r\n");
                    //对比
                    int flag=1;
                    for(int i = 0; i < 6; i++){
                        if(password[i]-temp[i]==0){
                            flag=0;
                            showStr("not equal  1");
                        }else{
                            showStr("equal  1");
                        }
                    }
                    if(flag==1){
                        ST7735_DrawString(10, 60, "PASSWORD RIGHT", RED, GRAY2, 1);

                        HAL_GPIO_WritePin(BEEP_GPIO_Port,BEEP_Pin,GPIO_PIN_SET);
                        HAL_Delay(500);
                        HAL_GPIO_WritePin(BEEP_GPIO_Port,BEEP_Pin,GPIO_PIN_RESET);
                        HAL_Delay(500);

                        //启动继电器

                    }else{
                        ST7735_DrawString(10, 60, "PASSWORD ERROR", RED, GRAY2, 1);
                    }
                    break;
                }
                default: {
                    StorePassword(key);
                    break;
                }
            }
        }
//            char str[20];  // 预留足够空间存储拼接后的字符�??
//            // 显示当前密码（用于调试）
//            snprintf(str, sizeof(str), "PASSWORD: %s", password);

//

            //ST7735_DrawString(10, 30, buffer, RED, GRAY2, 1);

            // 显示当前密码（用于调试）
//            snprintf(buffer, sizeof(buffer), "PASSWORD: %s", password);
//            ST7735_DrawString(10, 50, buffer, RED, GRAY2, 1);
            // �?? LED 控制移至任务2
//            osDelay(200); // 减少延迟时间
//        }

//        osDelay(100); // 适当延迟
    }
#endif
  /* USER CODE END StartTask02 */
}

/* USER CODE BEGIN Header_StartTask03 */
/**
* @brief Function implementing the myTask03_key0 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask03 */
void StartTask03(void const * argument)
{
  /* USER CODE BEGIN StartTask03 */
#ifdef TASK_CONTROL
    uint8_t buttonPressed = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET)
        {
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET && buttonPressed == 0)
            {
                buttonPressed = 1; // 标志按钮已按�????????

                if(mytTask1Handle == NULL)
                {
                    HAL_UART_Transmit(&huart1, (uint8_t *)"task1 not exist\n", sizeof("task1 not exist\n"), 200);
                    // 创建任务
                    osThreadDef(mytTask1, StartDefaultTask, osPriorityNormal, 0, 128);
                    mytTask1Handle = osThreadCreate(osThread(mytTask1), NULL);
                }
                else
                {
                    HAL_UART_Transmit(&huart1, (uint8_t *)"task1 deleted\n", sizeof("task1 deleted\n"), 200);
                    vTaskDelete(mytTask1Handle);
                    mytTask1Handle = NULL;
                }
            }
        }
        else
        {
            buttonPressed = 0; // 按钮松开时重置标志位
        }

        osDelay(100); // 延迟，防止任务占用过多CPU时间

    }
#endif

#ifdef QUEUE_TEST
    uint8_t buttonPressed = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    uint32_t data=888;
    BaseType_t m_flag;
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET){
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET && buttonPressed == 0)
            {
                buttonPressed = 1; // 标志按钮已按�????????
                //写入data �??????? queue 队列
                m_flag= xQueueSendToBack(myQueue01Handle,&data,200);
                if(pdPASS!=m_flag){
                    HAL_UART_Transmit(&huart1, (uint8_t *)"write 888 error\n", sizeof("write 888 error\n"), 200);
                }else{
                    HAL_UART_Transmit(&huart1, (uint8_t *)"write 888 to queue back\n", sizeof("write 888 to queue back\n"), 200);
                }
            }
        }else{
            buttonPressed = 0; // 按钮松开时重置标志位
        }
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif


#ifdef  QUEUESAMPOR
    uint8_t buttonPressed = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    BaseType_t m_flag;
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET){
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET && buttonPressed == 0)
            {
                buttonPressed = 1; // 标志按钮已按�????????
                m_flag= xSemaphoreGive(myCountingSem01Handle);
                if(m_flag==pdTRUE){
                    HAL_UART_Transmit(&huart1, (uint8_t *)"park ok\n", sizeof("park ok\n"), 200);
                }else{
                    HAL_UART_Transmit(&huart1, (uint8_t *)"park err\n", sizeof("park err\n"), 200);
                }
            }
        }else{
            buttonPressed = 0; // 按钮松开时重置标志位
        }
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef BINARY_SEMAPHOR
    uint8_t buttonPressed = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    BaseType_t m_flag;
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET){
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin) == GPIO_PIN_RESET && buttonPressed == 0)
            {
                buttonPressed = 1; // 标志按钮已按�????????
                m_flag= xSemaphoreGive(myBinarySemLEDHandle);
                if(m_flag==pdTRUE){
                    HAL_UART_Transmit(&huart1, (uint8_t *)"GET DATA OK SET SEMPHO0R\n", sizeof("GET DATA OK SET SEMPHO0R\n"), 200);
                }else{
                    HAL_UART_Transmit(&huart1, (uint8_t *)"GET DATA OK UNSET SEMPHO0R\n", sizeof("GET DATA OK UNSET SEMPHO0R\n"), 200);
                }
            }
        }else{
            buttonPressed = 0; // 按钮松开时重置标志位
        }
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef LED
    for(;;)
    {
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif
  /* USER CODE END StartTask03 */
}

/* USER CODE BEGIN Header_StartTask04 */
/**
* @brief Function implementing the myTask04_key1 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask04 */
void StartTask04(void const * argument)
{
  /* USER CODE BEGIN StartTask04 */
#ifdef TASK_CONTROL
    uint8_t buttonPressed = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????

    /* Infinite loop */
    for(;;)
    {
        if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET)
        {
            osDelay(10); // 消抖
            if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET && buttonPressed == 0)
            {
                buttonPressed = 1; // 标志按钮已按�????????

                if (flag == 1)
                {
                    HAL_UART_Transmit(&huart1, (uint8_t *)"task2 not suspend\n", sizeof("task2 not suspend\n"), 200);
                    vTaskSuspend(myTask02Handle);
                    flag = 0;
                }
                else
                {
                    HAL_UART_Transmit(&huart1, (uint8_t *)"task2 resume\n", sizeof("task2 resume\n"), 200);
                    vTaskResume(myTask02Handle);
                    flag = 1;
                }
            }
        }
        else
        {
            buttonPressed = 0; // 按钮松开时重置标志位
        }

        osDelay(100); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef QUEUE_TEST
    uint8_t buttonPressed1 = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    uint32_t data1=999;
    BaseType_t m_flag1;
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET){
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET && buttonPressed1 == 0)
            {
                buttonPressed1 = 1; // 标志按钮已按�????????
                //写入data �??????? queue 队列
                m_flag1= xQueueSendToBack(myQueue01Handle,&data1,200);
                if(pdPASS!=m_flag1){
                    HAL_UART_Transmit(&huart1, (uint8_t *)"write 999 error\n", sizeof("write 999 error\n"), 200);
                }else{
                    HAL_UART_Transmit(&huart1, (uint8_t *)"write 999 to queue back\n", sizeof("write 999 to queue back\n"), 200);
                }
            }
        }else{
            buttonPressed1 = 0; // 按钮松开时重置标志位
        }
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef  QUEUESAMPOR
    uint8_t buttonPressed = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    BaseType_t m_flag;
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET){
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET && buttonPressed == 0)
            {
                buttonPressed = 1; // 标志按钮已按�????????
                m_flag= xSemaphoreTake(myCountingSem01Handle,0);
                if(m_flag==pdTRUE){
                    HAL_UART_Transmit(&huart1, (uint8_t *)"driver ok\n", sizeof("driver ok\n"), 200);
                }else{
                    HAL_UART_Transmit(&huart1, (uint8_t *)"on car\n", sizeof("on car\n"), 200);
                }
            }
        }else{
            buttonPressed = 0; // 按钮松开时重置标志位
        }
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef BINARY_SEMAPHOR
    uint8_t buttonPressed = 0; // 标志位，0表示按钮未按下，1表示按钮已按�????????
    BaseType_t m_flag;
    /* Infinite loop */
    for(;;)
    {
        if(HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET){
            osDelay(10); // 消抖
            if(HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET && buttonPressed == 0)
            {
                buttonPressed = 1; // 标志按钮已按�????????
                m_flag= xSemaphoreTake(myBinarySemLEDHandle,0);
                if(m_flag==pdTRUE){
                    HAL_UART_Transmit(&huart1, (uint8_t *)"update DATA OK SET SEMPHO0R\n", sizeof("update DATA OK SET SEMPHO0R\n"), 200);
                }else{
                    HAL_UART_Transmit(&huart1, (uint8_t *)"update DATA OK UNSET SEMPHO0R\n", sizeof("update DATA OK UNSET SEMPHO0R\n"), 200);
                }
            }
        }else{
            buttonPressed = 0; // 按钮松开时重置标志位
        }
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif

#ifdef LED
    for(;;)
    {
        osDelay(1); // 延迟，防止任务占用过多CPU时间
    }
#endif
  /* USER CODE END StartTask04 */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

    void StorePassword(uint8_t key) {
        if (password_index < PASSWORD_LENGTH) {
            password[password_index++] = key;
            for(int i= password_index;i<PASSWORD_LENGTH;i++){
                password[i]='0';
            }

        } else {
            // 如果输入超过6位，则清空并从头�??�??
            memset(password, 0, sizeof(password));
            for(int i= 0;i<PASSWORD_LENGTH;i++){
                password[i]='0';
            }
            password_index = 0;
            password[password_index++] = key;
        }
         ST7735_DrawString(10, 50, password, RED, GRAY2, 1);

    }

    void DeleteLastCharacter(void) {
        if (password_index > 0) {
            password[--password_index] = 0; // 将最后一个字符置�??0
            for(int i= password_index;i<PASSWORD_LENGTH;i++){
                password[i]='0';
            }


            ST7735_DrawString(10, 50, password, RED, GRAY2, 1);

        }
    }

    void ClearPassword(void) {
        memset(password, 0, sizeof(password));
        password_index = 0;
        for(int i= 0;i<PASSWORD_LENGTH;i++){
            password[i]='0';
        }
        ST7735_DrawString(10, 50, password, RED, GRAY2, 1);
    }


    void Format_display(char detect){
        char message[50];
        int index=0;
        const char *prefix="CURRENT VALUE IS:";
        while(*prefix){
            message[index++]=*prefix++;
        }
        message[index++]=detect;
        message[index++]='\0';

        ST7735_DrawString(10, 30, message, RED, GRAY2, 1);
    }

void Format_display_ty(char *origin,char *detect){
    if(origin==NULL||detect==NULL){
        return;
    }
    char *end_origin=origin+ strlen(origin);

    while(*detect!='\0'){
        *end_origin+=*detect++;
    }

    *end_origin+='\0';

    ST7735_DrawString(10, 60, end_origin, RED, GRAY2, 1);
}
/* USER CODE END Application */

